﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Newtonsoft.Json;

namespace RN.ERP.Web.Person
{
    public partial class PersonEmpCertCodeValid : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (!string.IsNullOrEmpty(Request.QueryString["manual"]))
                {
                    hdManualID.Value = Request.QueryString["manual"];
                }
                if (Request.Params["action"] != null)
                {
                    string action = Request.Params["action"];
                    switch (action)
                    {
                        case "GetQualitiesDic":
                            GetQualitiesDic();
                            break;
                    }
                }
            }
        }
        /// <summary>
        /// 取得数据
        /// </summary>
        private void GetQualitiesDic()
        {
            string rootCode = string.Empty;
            int parentId = 0;
            string childRootCode = string.Empty;
            if (Request.Params["rootCode"] == null)
            {
                var result1 = "[]";
                OutputData(result1);
                return;
            }
            rootCode = Request.Params["rootCode"];
            if (Request.Params["childRootCode"] != null)
            {
                childRootCode = Request.Params["childRootCode"];
            }
            if (Request.Params["parentId"] != null)
            {
                int.TryParse(Request.Params["parentId"].ToString(), out parentId);
            }
            using (BasicService.BasicServiceClient client = new BasicService.BasicServiceClient())
            {
                //返回全部证书类型
                OutputData(client.GetQualitiesDicAll(rootCode, parentId.ToString(), childRootCode));
                return;
            }
        }
        /// <summary>
        /// 输出JSON格式数据到页面
        /// </summary>
        /// <param name="dataStr"></param>
        private void OutputData(string dataStr)
        {
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(dataStr);
            HttpContext.Current.Response.End();
        }
    }
}